package com.rs.admin.controller.sy;


import com.rs.admin.common.RespResult;
import com.rs.admin.mapper.UserInfoMapper;
import com.rs.admin.module.UserInfo;
import com.rs.admin.module.ao.LoginAO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 系统用户管理
 */
@Slf4j
//@Api(tags = "用户管理")
@RestController
@RequestMapping("user")
public class UserInfoController {

    @Resource
    UserInfoMapper userInfoMapper;

//    @ApiOperation("新增用户")
    @PostMapping("/createUser")
    public RespResult createUser(@RequestBody LoginAO userInfo) {

        if (StringUtils.isEmpty(userInfo.getName()) || StringUtils.isEmpty(userInfo.getPassword())) {
            RespResult.buildFail("请输入 用户名和密码");
        }

        userInfo.setPassword(DigestUtils.md5Hex(userInfo.getPassword() + userInfo.getPassword()));

        UserInfo user = new UserInfo();
        BeanUtils.copyProperties(userInfo,user);
        userInfoMapper.insert(user);

        return RespResult.buildSuccess();

    }


}
